<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$type=empty($_GPC['type']) ? 'all' :$_GPC['type'];
$state=$_GPC['state'];
$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
$where="WHERE a.uniacid=:uniacid and c.state=2";
$data[':uniacid']=$_W['uniacid'];

if(isset($_GPC['keywords'])){
    $where.="  and b.title LIKE  concat('%', :name,'%')";
    $data[':name']=$_GPC['keywords']; 
    $type='all';  
}
 if($type!='all'){
    $where.=" and a.state={$state}";
}
// if (isset($_GPC['id'])) {
//     $where.= "and a.unit_id=".$_GPC['id'];
// }
$sql="SELECT a.*,b.title,b.video,c.students_name,d.class_name,f.course_name,g.cate_name FROM ".tablename('snx_answer'). " a"  . " left join " . tablename("snx_task") . " b on a.task_id=b.id " . " left join " . tablename("snx_users") . " c on a.u_id=c.id ". " left join " . tablename("snx_class") . " d on c.class_id=d.id "." left join " . tablename("snx_course") . " e on d.cou_id=e.id left join" .tablename('snx_coursecate') ."f on e.c_id=f.id left join".tablename('snx_school') ."g on f.school_id=g.id "  .$where." ORDER BY a.create_time desc";
$total=pdo_fetchcolumn("SELECT  count(*) FROM ".tablename('snx_answer'). " a"  . " left join " . tablename("snx_task") . " b on a.task_id=b.id " . " left join " . tablename("snx_users") . " c on a.u_id=c.id ". " left join " . tablename("snx_class") . " d on c.class_id=d.id "  .$where." ORDER BY a.create_time desc",$data);
$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$list=pdo_fetchall($select_sql,$data);
$pager = pagination($total, $pageindex, $pagesize);

if($_GPC['op']=='delete'){
    $res=pdo_delete('snx_answer',array('id'=>$_GPC['id']));
    if($res){
        message('删除成功！', $this->createWebUrl('examinetask',array('id'=>$_GPC['id1'])), 'success');
    }else{
        message('删除失败！','','error');
    }
}

if($_GPC['op']=='change'){
        $res = pdo_update('snx_answer',array('state'=>$_GPC['state']),array('id'=>$_GPC['id']));
        if($res){
         message('改变成功！', $this->createWebUrl('examinetask'), 'success');
        }else{
              message('改变失败！','','error');
        }
    }

include $this->template('web/examinetask');